import axios from 'axios'
import {Toast} from 'vant'

// axios 配置
axios.defaults.timeout = 10000;
axios.defaults.baseURL = 'http://localhost:3000';

//返回状态判断
axios.interceptors.response.use((res) => {
	if (res.data.code !== 200) {
   Toast('网络异常')
		return Promise.reject(res);
	}
	return res;
}, (error) => {
 Toast('网络异常')
	return Promise.reject(error);
});

export function fetchGet(url, param) {
  return new Promise((resolve, reject) => {
    axios.get(url, {
        params: param
      })
      .then(response => {
        resolve(response.data)
      }, err => {
        reject(err)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
